package com.genesis.yunnanji.utils;

import com.zhy.http.okhttp.callback.Callback;

import org.json.JSONObject;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by Administrator on 2017/7/20.
 */

public abstract class NetWorkCallBack extends Callback<JSONObject> {
    @Override
    public JSONObject parseNetworkResponse(Response response, int id) throws Exception {
        String s = response.body().string();
        JSONObject jsonObject = new JSONObject(s);
        if (jsonObject.optInt("code") == 2) {//获取成功
            getSuccess();
        } else if (jsonObject.optInt("code") == 1) {//没有更多数据
            noMoreData();
        } else if (jsonObject.optInt("code") == 4) {//暂无相关数据
            noData();
        }
        return jsonObject;
    }

    @Override
    public void onError(Call call, Exception e, int id) {
    }

    protected abstract void getSuccess();

    protected abstract void noMoreData();

    protected abstract void noData();

}
